import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
// import 'package:flutterapp6/cart/catr_info.dart';
// import 'package:flutterapp6/provied/cartmodel.dart';
import '../cart/catr_info.dart';
import '../provied/cartmodel.dart';
import '../config/api.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
//import 'package:flutter_banner_swiper/flutter_banner_swiper.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../provied/cartmodel.dart';
//import '../model/cart.dart';
import 'dart:convert';
//import '../button/button.dart';
class GoodsCommodity extends StatefulWidget {
  Map arguments;
  GoodsCommodity({Key key, this.arguments}) : super(key: key);
  // Goods(this.arguments);
  @override
  _GoodsCommodityState createState() =>
      _GoodsCommodityState(arguments: this.arguments);
  // _GoodsCommodityState createState() => _GoodsCommodityState(arguments:this.arguments);
}

class _GoodsCommodityState extends State<GoodsCommodity> {
  Map arguments;
  int count = 1;
  Map<String, dynamic> map;
  Map m1 = {
    "message": [
      {
        "url": "http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e",
      }
    ]
  };
  Map m;
  int a;
  List url = [];
  bool flags;
  _GoodsCommodityState({this.arguments});
  bool flag = false;
  List<Map> g = [
    {
      "id": 0,
      "check": false,
    },
    {
      "id": 1,
      "check": false,
    },
    {
      "id": 2,
      "check": false,
    }
  ];
  @override
  void initState() {
    super.initState();
    
    //  this.getgoods(arguments['id']);
    print('${arguments['id']}没有初始值吗');
    _getlist(arguments['id']);
    setState(() {
      m = arguments['id'];
      this.flag = true;
      this._tit();
      this._tit1();
       context.read<CartProvide>().add();
       context.read<CartProvide>().getUsers();
      //this.localstare();
    });
  }

  //添加商品的数据
  Map goods;
  // Map   goods={
  //       "goodsname":null,
  //       "goodsId":null,
  //       "count":null,
  //        "price":null,
  //        "images":null,
  //        "check":true,
  //        "tit":null
  // };
  localstare(goods) {
    //print(goods);
  //  Cartprovied().save(goods);
  }

  List<Map> v = [];
  _tit() {
    int n = 0;
    m['titxx'].split(',').forEach((item) {
      if (item != '') {
        print(item);
        setState(() {
          v.add({"id": n, "tit": item, "check": false});
          n++;
        });
      }
      // return v;
    });
// notifyListeners();
  }

  List<Map> v1 = [];
  _tit1() {
    int n1 = 0;
    m['tit'].split(',').forEach((item) {
      print(item);
      if (item != '') {
        print(item);
        setState(() {
          v1.add({"id": n1, "tit": item, "check": false});
          n1++;
        });
      }
      // return v;
    });
// notifyListeners();
  }

  String pricename;
  String pricename1;
  bool ly = false;
  List<Widget> tit() => List.generate(v.length, (index) {
        final ValueNotifier<List> _counter = ValueNotifier<List>([]);
        final Widget goodJob = const Mybutton(text: '你好');
        return ValueListenableBuilder(
            //  valueListenable: null,
            valueListenable: _counter,
            child: Text('你还'),
            builder: (BuildContext context, value, Widget child) {
              return Container(
                margin: EdgeInsets.fromLTRB(0, 0, 5, 5),
                child: Mybutton(
                  color: v[index]['check'] ? Colors.orangeAccent : Colors.white,
                  text: '${v[index]['tit']}',
                  pressed: () {
                    //  Navigator.of(context).pop(null);
                    // Navigator.push(showModalBottomSheet());
                   
                    //print('爱意${index}');
                    setState(() {
                      context.read<CartProvide>().add();
                     // Provider.of<CartProvide>(context).add();
                     // CartProvide().add();
                      // CartProvide().add();
                      // showModalBottomSheet();
                      this.ly = !this.ly;
                      pricename = v[index]['tit'];
                      // print(_counter.value);
                      //   this.b=index;
                      // v.forEach((item) {
                      //   if(item['id']!=index){
                      //    item['check']=false;
                      //   // print(item['check']);
                      //   }else{
                      //     item['check']=!item['check'];
                      //   }
                      // });
                      _counter.value = v;
                     // print(_counter.value[index]['id']);
                      _counter.value.forEach((item) {
                        if (item['id'] != index) {
                          item['check'] = false;

                          // print(item['check']);
                          //  this.tit();
                          // Navigator.of(context).pop(null);
                        } else {
                          item['check'] = !item['check'];
                          //   Navigator.of(null);
                          //  Navigator.of(context).pop(null);
                        }

                        // return v = _counter.value;
                      });
                    //  print(v);
                      // Navigator.pop(context);
                    });
                    // Navigator.of(context);
                    //this._dialo();
                    Navigator.of(context).pop();
                    // Navigator.of(context).pop(null);
                    // Navigator.of(null);
                    this._dialo();
                  },
                ),
              );
            });
      });
  // void getgoods(v) {
  //   goodsdetail(v).then((value) => {
  //         setState(() {
  //           a = v;
  //           m = value.data;
  //           this.flag=true;
  //           print(m['message'][0]['url'].split(',')[0]);
  //         })
  //       });
  // }
//2
  List<Widget> tits() => List.generate(v1.length, (index) {
        final ValueNotifier<List> _counter = ValueNotifier<List>([]);
        final Widget goodJob = const Mybutton(text: '你好');
        return ValueListenableBuilder(
            //  valueListenable: null,
            valueListenable: _counter,
            child: Text('ni'),
            builder: (BuildContext context, value, Widget child) {
              return Container(
                margin: EdgeInsets.fromLTRB(0, 0, 5, 5),
                child: Mybutton(
                  color: v1[index]['check'] ? Colors.black38 : Colors.white,
                  text: '${v1[index]['tit']}',
                  //${v[index]['tit']}
                  pressed: () {
                    //  Navigator.pop(context);
                    //Navigator.of(context).pop();
                    // Navigator.pop(context);
                    print('爱意${index}');
                    setState(() {
                      //this.ly = !this.ly;
                      pricename1 = v1[index]['tit'];
                      _counter.value = v1;
                      print(_counter.value[index]['id']);
                      _counter.value.forEach((item) {
                        if (item['id'] != index) {
                          item['check'] = false;
                          // print(item['check']);
                          //this.tit();
                        } else {
                          item['check'] = !item['check'];
                        }
                        return v1 = _counter.value;
                      });
                      print(value);
                    });
                    Navigator.of(context).pop();
                    this._dialo();
                  },
                ),
              );
            });
      });
  List<Widget> geturl() {
    List<Widget> list = new List();
    for (var i = 0; i < url.length; i++) {
      list.add(Image.network(url[i], fit: BoxFit.cover));
    }
    // print(this.url);
    return list.toList();
  }

  int counts = 1;
  _dialo() {
    return showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return GestureDetector(
          child: Container(
              height: 700.0,
              color: Color(0xfff1f1f1),
              child: Column(
                children: <Widget>[
                  //商品参数选择信息头部
                  Container(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Container(
                          margin: EdgeInsets.all(10),
                          width: 120,
                          height: 140,
                          child: Image.network(m['url'].split(',')[0],
                              fit: BoxFit.cover),
                        ),
                        Container(
                          // decoration: BoxDecoration(
                          //   border: Border(
                          //       bottom: BorderSide(
                          //           width: 1,
                          //           color: Colors
                          //               .black38)),
                          // ),
                          margin: EdgeInsets.fromLTRB(0, 30, 0, 20),
                          width: 160,
                          height: 120,
                          child: ListView(
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text('￥',
                                      style: TextStyle(
                                          color: Colors.redAccent,
                                          fontSize: 12)),
                                  Text('${m['price']}.00',
                                      style: TextStyle(
                                          color: Colors.redAccent,
                                          fontSize: 18,
                                          fontWeight: FontWeight.w700)),
                                ],
                              ),
                              SizedBox(
                                height: 5,
                              ),
                              Text('库存${m['price'] + 50}件',
                                  style: TextStyle(color: Colors.black26)),
                              //请选择 颜色分类 尺码
                              SizedBox(height: 5),
                              Row(
                                children: <Widget>[
                                  Text(
                                    '${pricename == null ? '请选择' : pricename}',
                                  ),
                                  Text(
                                    '${pricename1 == null ? '选择规格' : pricename1}',
                                  )
                                ],
                              )
                            ],
                          ),
                        ),
                        //关闭按钮
                        IconButton(
                            icon: Icon(Icons.highlight_off),
                            onPressed: () {
                              Navigator.pop(context);
                            }),
                      ],
                    ),
                  ),
                  //商品参数选择区域
                  Container(
                    decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(width: 1, color: Colors.black38)),
                    ),
                    //padding: EdgeInsets.fromLTRB(left, top, right, bottom),
                    margin: EdgeInsets.fromLTRB(10, 0, 10, 0),
                    width: double.infinity,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text('尺码'),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Expanded(
                              // width: 375,
                              // height: 100,
                              child: Wrap(
                                  //alignment: WrapAlignment.spaceEvenly,
                                  spacing: 2,
                                  runSpacing: 2,
                                  children: tit()),
                            )
                          ],
                        ),
                        Container(
                          decoration: BoxDecoration(
                            border: Border(
                                bottom: BorderSide(
                                    width: 1, color: Colors.black38)),
                          ),
                        ),
                      ],
                    ),
                  ),
                  //商品规格区域
                  Container(
                    decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(width: 1, color: Colors.black12)),
                    ),
                    margin: EdgeInsets.fromLTRB(10, 0, 10, 5),
                    width: double.infinity,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text('规格'),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Expanded(
                              // width: 375,
                              // height: 100,
                              child: Wrap(
                                  //alignment: WrapAlignment.spaceEvenly,
                                  spacing: 2,
                                  runSpacing: 2,
                                  children: tits()),
                            )
                          ],
                        ),
                        Container(
                          decoration: BoxDecoration(
                            border: Border(
                                bottom: BorderSide(
                                    width: 1, color: Colors.black38)),
                          ),
                        ),
                        Row(
                          //  mainAxisAlignment: MainAxisAlignment.end,
                          children: <Widget>[
                            IconButton(
                                icon: Icon(
                                  Icons.remove,
                                  color: counts == 1
                                      ? Colors.black12
                                      : Colors.black,
                                ),
                                onPressed: () {
                                  setState(() {
                                    if (counts <= 1) {
                                      return counts = 1;
                                    } else {
                                      counts--;
                                    }
                                    Navigator.of(context).pop();
                                    this._dialo();
                                  });
                                }),
                            Container(
                              child: Text('${counts}'),
                            ),
                            IconButton(
                                icon: Icon(
                                  Icons.add,
                                  color: Colors.black,
                                ),
                                onPressed: () {
                                  setState(() {
                                    counts++;
                                    // counts=counts>=10?10:counts++;
                                  });
                                  Navigator.of(context).pop();
                                  this._dialo();
                                  print(counts);
                                })
                          ],
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            Container(
                              width: 100,
                              // color: Colors.redAccent,
                              child: RaisedButton(
                                  color: Colors.red[300],
                                  textColor: Colors.white,
                                  onPressed: () {
                                    setState(() {
                                      var goodsname=m['goodsname'];
                                      var goodsId=m['id'];
                                      var count=this.counts;
                                      var price=m['price'];
                                      var images=m['url'].split(',')[0];
                                      var tit=this.pricename + this.pricename1;
                                     // CartProvide().getcartinfo();
                                     // CartProvide().detailremove(goodsId);
                                   // CartProvide().checkState(goodsId);
                                      CartProvide().save(goodsId, goodsname, count, price, images, tit);
                                      CartProvide().getcartinfo();
                                    });
                                   // localstare(json.encode(goods));
                                   // print(json.encode(goods));
                                    Navigator.of(context).pop();
                                     Navigator.of(context).pushNamed('/cart');
                                  },
                                  child: Text('立即购买')),
                            )
                          ],
                        )
                      ],
                    ),
                  )
                ],
              )),
          onTap: () => false,
        );
      },
    );
  }

  Widget _listItem(BuildContext context, int index) {
    return
        //Stack(
        //children: <Widget>[
        Column(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
      Container(
        padding: EdgeInsets.all(5),
        decoration: BoxDecoration(
            //  border: ,
            //color: Colors.red,
            borderRadius: BorderRadius.circular(25)),
        child: AspectRatio(
          aspectRatio: 16 / 10,
          child: Swiper(
            itemBuilder: (BuildContext context, int index) {
              return ClipRRect(
                  borderRadius: BorderRadius.circular(10),
                  child: Image.network(m['url'].split(',')[index],
                      fit: BoxFit.cover)
                  // Image.network(
                  //     'http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e',
                  //     fit: BoxFit.cover)
                  //  Image.network(m==null?m1['message']['url']:m['message'][0]['url'].split(',')[index], fit: BoxFit.cover)
                  // Image.network(map==null?imglist[index]['url']:map['message'][index]['img'], fit: BoxFit.cover),
                  );
            },
            //itemCount: 2,
            itemCount: m['url'].split(',').length - 1,
            onTap: (index) {
              // getList();
              // Navigator.pushNamed(context, '/homedetail',
              //     arguments: {"id": this.imglist[index]['id']});
              //  print('点击了${this.imglist[index]['id']}');
            },
            pagination: SwiperPagination(
                builder: DotSwiperPaginationBuilder(
              color: Colors.white,
              //  color: Color.fromRGBO(200, 200, 200, 0.5),
              size: 8.0,
              activeSize: 10.0,
            )),
            // control: SwiperControl(
            //     color: Theme.of(context).primaryColor.withOpacity(.5)
            //     ),
            loop: true,
            autoplay: true,
          ),
        ),
      ),
      //商品参数
      Container(
        width: double.infinity,
        padding: EdgeInsets.all(10),
        child: Card(
          elevation: 2.0,
          clipBehavior: Clip.antiAlias,
          child: Column(
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(left: 5),
                    width: 40,
                    height: 25,
                    child: RaisedButton(
                      child: Text(
                        '滢',
                        style: TextStyle(fontSize: 12),
                        maxLines: 1,
                        textAlign: TextAlign.center,
                      ),
                      color: Colors.red,
                      textColor: Colors.white,
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10)),
                      onPressed: () {},
                    ),
                  ),
                  Container(
                      margin: EdgeInsets.only(right: 5),
                      child:
                          Text('月销50', style: TextStyle(color: Colors.black12)))
                ],
              ),
              Container(
                margin: EdgeInsets.fromLTRB(10, 2, 10, 5),
                child: Text(
                  '${m['goodsname']}',
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      color: Colors.black,
                      fontSize: 16,
                      fontWeight: FontWeight.w500),
                ),
              ),
              Container(
                  margin: EdgeInsets.only(left: 10),
                  width: double.infinity,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        '价格${m['price']}.00元',
                        style: TextStyle(color: Colors.redAccent),
                        textAlign: TextAlign.start,
                      ),
                      SizedBox(
                        width: 10,
                      ),
                      Text(
                        '${m['price'] + 50}.00',
                        style: TextStyle(
                            color: Colors.black26,
                            decoration: TextDecoration.lineThrough,
                            fontSize: 12),
                        textAlign: TextAlign.start,
                      )
                    ],
                  )),
              Container(
                  margin: EdgeInsets.fromLTRB(10, 2, 10, 0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        '七天无理由',
                        style: TextStyle(color: Colors.black26, fontSize: 12),
                      ),
                      Text('免运费',
                          style:
                              TextStyle(color: Colors.black26, fontSize: 12)),
                      Text('保障',
                          style: TextStyle(color: Colors.black26, fontSize: 12))
                    ],
                  )),
              Container(
                  margin: EdgeInsets.fromLTRB(10, 0, 10, 5),
                  //padding: EdgeInsets.fromLTRB(left, top, right, bottom),
                  // padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
                  decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(width: 1, color: Colors.black38)),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text('选择',
                          style:
                              TextStyle(color: Colors.black38, fontSize: 16)),
                      IconButton(
                          icon: Icon(Icons.chevron_right),
                          onPressed: () {
                            this._dialo();
                            // showModalBottomSheet(
                            //   context: context,
                            //   builder: (BuildContext context) {
                            //     return GestureDetector(
                            //       child: Container(
                            //           // height: 2000.0,
                            //           color: Color(0xfff1f1f1),
                            //           child: Column(
                            //             children: <Widget>[
                            //               //商品参数选择信息头部
                            //               Container(
                            //                 child: Row(
                            //                   mainAxisAlignment:
                            //                       MainAxisAlignment
                            //                           .spaceBetween,
                            //                   crossAxisAlignment:
                            //                       CrossAxisAlignment.start,
                            //                   children: <Widget>[
                            //                     Container(
                            //                       margin: EdgeInsets.all(10),
                            //                       width: 120,
                            //                       height: 140,
                            //                       child: Image.network(
                            //                           m['url'].split(',')[0],
                            //                           fit: BoxFit.cover),
                            //                     ),
                            //                     Container(
                            //                       // decoration: BoxDecoration(
                            //                       //   border: Border(
                            //                       //       bottom: BorderSide(
                            //                       //           width: 1,
                            //                       //           color: Colors
                            //                       //               .black38)),
                            //                       // ),
                            //                       margin: EdgeInsets.fromLTRB(
                            //                           0, 30, 0, 20),
                            //                       width: 160,
                            //                       height: 120,
                            //                       child: ListView(
                            //                         children: <Widget>[
                            //                           Row(
                            //                             children: <Widget>[
                            //                               Text('￥',
                            //                                   style: TextStyle(
                            //                                       color: Colors
                            //                                           .redAccent,
                            //                                       fontSize:
                            //                                           12)),
                            //                               Text(
                            //                                   '${m['price']}.00',
                            //                                   style: TextStyle(
                            //                                       color: Colors
                            //                                           .redAccent,
                            //                                       fontSize: 18,
                            //                                       fontWeight:
                            //                                           FontWeight
                            //                                               .w700)),
                            //                             ],
                            //                           ), 
                            //                           SizedBox(
                            //                             height: 5,
                            //                           ),
                            //                           Text(
                            //                               '库存${m['price'] + 50}件',
                            //                               style: TextStyle(
                            //                                   color: Colors
                            //                                       .black26)),
                            //                           //请选择 颜色分类 尺码
                            //                           SizedBox(height: 5),
                            //                           Text(
                            //                             '${pricename + pricename1}',
                            //                           )
                            //                         ],
                            //                       ),
                            //                     ),
                            //                     //关闭按钮
                            //                     IconButton(
                            //                         icon: Icon(
                            //                             Icons.highlight_off),
                            //                         onPressed: () {
                            //                           Navigator.pop(context);
                            //                         }),
                            //                   ],
                            //                 ),
                            //               ),
                            //               //商品参数选择区域
                            //               Container(
                            //                 decoration: BoxDecoration(
                            //                   border: Border(
                            //                       bottom: BorderSide(
                            //                           width: 1,
                            //                           color: Colors.black38)),
                            //                 ),
                            //                 margin: EdgeInsets.fromLTRB(
                            //                     10, 0, 10, 5),
                            //                 width: double.infinity,
                            //                 child: Column(
                            //                   mainAxisAlignment:
                            //                       MainAxisAlignment.start,
                            //                   crossAxisAlignment:
                            //                       CrossAxisAlignment.start,
                            //                   children: <Widget>[
                            //                     Text('尺码'),
                            //                     Row(
                            //                       mainAxisAlignment:
                            //                           MainAxisAlignment.start,
                            //                       crossAxisAlignment:
                            //                           CrossAxisAlignment.start,
                            //                       children: <Widget>[
                            //                         Expanded(
                            //                           // width: 375,
                            //                           // height: 100,
                            //                           child: Wrap(
                            //                               //alignment: WrapAlignment.spaceEvenly,
                            //                               spacing: 2,
                            //                               runSpacing: 2,
                            //                               children: tit()
                            //                               ),
                            //                         )
                            //                       ],
                            //                     ),
                            //                     Container(
                            //                       decoration: BoxDecoration(
                            //                         border: Border(
                            //                             bottom: BorderSide(
                            //                                 width: 1,
                            //                                 color: Colors
                            //                                     .black38)),
                            //                       ),
                            //                     ),
                            //                   ],
                            //                 ),
                            //               ),
                            //               //商品规格区域
                            //                     Container(
                            //                 decoration: BoxDecoration(
                            //                   border: Border(
                            //                       bottom: BorderSide(
                            //                           width: 1,
                            //                           color: Colors.black12)),
                            //                 ),
                            //                 margin: EdgeInsets.fromLTRB(
                            //                     10, 0, 10, 5),
                            //                 width: double.infinity,
                            //                 child: Column(
                            //                   mainAxisAlignment:
                            //                       MainAxisAlignment.start,
                            //                   crossAxisAlignment:
                            //                       CrossAxisAlignment.start,
                            //                   children: <Widget>[
                            //                     Text('规格'),
                            //                     Row(
                            //                       mainAxisAlignment:
                            //                           MainAxisAlignment.start,
                            //                       crossAxisAlignment:
                            //                           CrossAxisAlignment.start,
                            //                       children: <Widget>[

                            //                         Expanded(
                            //                           // width: 375,
                            //                           // height: 100,
                            //                           child: Wrap(
                            //                               //alignment: WrapAlignment.spaceEvenly,
                            //                               spacing: 2,
                            //                               runSpacing: 2,
                            //                               children: tits()
                            //                               ),
                            //                         )
                            //                       ],
                            //                     ),
                            //                     Container(
                            //                       decoration: BoxDecoration(
                            //                         border: Border(
                            //                             bottom: BorderSide(
                            //                                 width: 1,
                            //                                 color: Colors
                            //                                     .black38)),
                            //                       ),
                            //                     ),
                            //                   ],
                            //                 ),
                            //               )
                            //             ],
                            //           )
                            //           ),
                            //       onTap: () => false,
                            //     );
                            //   },
                            // );
                          })
                    ],
                  )),
              //  RaisedButton(
              //   onPressed: () {

              //   }
              //  )
            ],
          ),
        ),
      ),
      Container(
        width: double.infinity,
        margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
        child: Text(
          '商品详图',
          textAlign: TextAlign.center,
          style: TextStyle(
            fontSize: 22,
            fontWeight: FontWeight.w400,
          ),
        ),
      ),
      // RaisedButton(
      //     child: Text('打电话'),
      //     onPressed: () {
      //        _luancherurl();
      //     }),
      // _banel(context, m['banelurl'].split(',').length-2)
      // ListView.builder(itemBuilder: _banel,itemCount:1)
      _listbanel()
    ]);
  }

  Widget _listbanel() {
    List<Widget> banel = [];
    List bel = [];
    Widget content;
    bel.addAll(m['banelurl'].split(','));
    // print('${bel.length}没有长度吗');
    for (var item in bel) {
      if (item != ',') {
        banel.add(Container(
            width: double.infinity,
            // height: double.infinity,
            //padding: EdgeInsets.all(10),
            child: Image.network(item, fit: BoxFit.cover)));
      }
    }
    content = Column(
      children: banel,
    );
    return content;
    // return m['banelurl'].split(',').map((f)=>Image.network(f,fit:BoxFit.cover,)).toList();
  }

  Widget _banel(BuildContext context, int index) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Image.network(m['banelurl'].split(',')[index], fit: BoxFit.cover)
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    // print(url);
    // geturl();
    if (this.flag) {
      this.tit();
      return Scaffold(
          appBar: AppBar(
            title: Text(
              '商品详情',
              textAlign: TextAlign.right,
            ),
          ),
          body: Stack(
            children: <Widget>[
              ListView.builder(itemCount: 1, itemBuilder: _listItem),
              Container(
                // decoration: BoxDecoration(
                //   color: Colors.white,
                // ),
                // color: Colors.white,
                child: Positioned(
                    // top: 0,
                    bottom: 0,
                    child: Row(
                      children: <Widget>[
                        Container(
                          width: ScreenUtil().setWidth(140),
                          color: Colors.white,
                          child: IconButton(
                              icon: Icon(Icons.star_border), onPressed: null),
                        ),
                        Container(
                            color: Colors.white,
                            child: Stack(
                              children: <Widget>[
                                Positioned(
                                  child: IconButton(
                                      icon: Icon(Icons.shopping_cart),
                                      onPressed: null),
                                ),
                                Positioned(
                                    top: 7,
                                    right: 12,
                                    child: Container(
                                      width: 15,
                                      height: 15,
                                      decoration: BoxDecoration(
                                        color: Colors.red[100],
                                        borderRadius: BorderRadius.circular(10),
                                      ),
                                      child: Text(
                                        '${allcount}',
                                        textAlign: TextAlign.center,
                                        style: TextStyle(color: Colors.white),
                                      ),
                                    ))
                              ],
                            )),
                        Container(
                          width: ScreenUtil().setWidth(280),
                          color: Colors.white,
                          child: RaisedButton(
                              color: Colors.orangeAccent,
                              onPressed: (){
                                setState(() {
                                  this._dialo();
                                });
                              },
                              child: Text(
                                '加入购物车',
                                style: TextStyle(
                                    color: Colors.white,
                                    fontWeight: FontWeight.w500),
                              )),
                        ),
                        Container(
                          width: ScreenUtil().setWidth(280),
                          color: Colors.white,
                          child: RaisedButton(
                              color: Colors.red,
                              onPressed: () {
                                setState(() {
                                  this._dialo();
                                });
                               // localstare('我是');
                              },
                              child: Text(
                                '立即购买',
                                style: TextStyle(
                                    color: Colors.white,
                                    fontWeight: FontWeight.w500),
                              )),
                        ),
                      ],
                    )),
              )
            ],
          ));
    } else {
      return Scaffold(
        appBar: AppBar(),
        body: Text(
          '数据加载中....',
          style: TextStyle(color: Colors.grey),
          textAlign: TextAlign.center,
        ),
      );
    }
  }

  void _luancherurl() async {
    String url = 'http://dbyxs.xyz';
    //  String url='tel:'+'15862637996';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      print('访问失败');
    }
  }
}

int c;
_getlist(v) {
  setState() {
    c = v;
  }
  // return v;
//  print('没有id${v}');
}
//  Container(
//   child:
//  Column(
//    mainAxisAlignment: MainAxisAlignment.start,
//   children:  ListView.builder(itemCount: 1, itemBuilder: _listItem)

// ),
// ),
//Text('数据加载中'),
//   Container(
//    child:
// Column(
//      mainAxisAlignment: MainAxisAlignment.start,
//   children: <Widget>[
//     Container(
//       padding: EdgeInsets.all(5),
//       decoration: BoxDecoration(
//           //  border: ,
//           //color: Colors.red,
//           borderRadius: BorderRadius.circular(25)),
//       child: AspectRatio(
//         aspectRatio: 16 / 10,
//         child: Swiper(
//           itemBuilder: (BuildContext context, int index) {
//             return ClipRRect(
//               borderRadius: BorderRadius.circular(10),
//               child:
//             // Image.network(m['message'][0]['url'].split(',')[index], fit: BoxFit.cover)
//            // Image.network('http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e',fit:BoxFit.cover)
//              Image.network(m==null?m1['message']['url']:m['message'][0]['url'].split(',')[index], fit: BoxFit.cover)
//                  // Image.network(map==null?imglist[index]['url']:map['message'][index]['img'], fit: BoxFit.cover),
//             );
//           },
//         //  itemCount:1,
//           itemCount: m['message'][0]['url'].split(',').length -1 ,
//           onTap: (index) {
//             // getList();
//             // Navigator.pushNamed(context, '/homedetail',
//             //     arguments: {"id": this.imglist[index]['id']});
//           //  print('点击了${this.imglist[index]['id']}');
//           },
//           pagination: SwiperPagination(
//               builder: DotSwiperPaginationBuilder(
//                 color: Colors.white,
//           //  color: Color.fromRGBO(200, 200, 200, 0.5),
//             size: 8.0,
//             activeSize: 10.0,
//           )),
//           // control: SwiperControl(
//           //     color: Theme.of(context).primaryColor.withOpacity(.5)
//           //     ),
//           loop: true,
//           autoplay: true,
//         ),
//       ),
//     ),
//     RaisedButton(
//       child:Text('打电话'),
//       onPressed:(){
//         _luancherurl();
//       }
//     ),
//   ]
//    ),
// ),
//按钮组件
class Mybutton extends StatelessWidget {
  final text;
  final pressed;
  final color;
  // ButtonPage({this.text='',this.pressed,}) :super({key:Key});
  const Mybutton({this.text = '', this.pressed = null, this.color});

  @override
  Widget build(BuildContext context) {
    return
        // Expanded(
        // child:
        Container(
      width: 70,
      margin: EdgeInsets.fromLTRB(0, 3, 0, 0),
      height: 30,
      child: RaisedButton(
        color: this.color,
        child: Text(this.text),
        onPressed: this.pressed,
      ),
    );
    // );
  }
  // _ButtonPageState createState() => _ButtonPageState(this.text);
}
